package com.doliere.android.app.p2p.serviceinfos;

import java.nio.channels.AsynchronousCloseException;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

import com.doliere.android.app.p2p.listeners.P2pActionListener;

import android.annotation.SuppressLint;
import android.net.wifi.p2p.WifiP2pInfo;
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.p2p.WifiP2pManager.Channel;
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceInfo;
import android.os.AsyncTask;
import android.widget.Toast;

/**
 * 
 * @author doliere
 * This class holds information about the
 * SISMAPP service that will be registered for service discovery.
 * 3 fields : service_name, listening port and user_name.
 */
public final class P2pServiceInfo{
	
	
	private final String SERVICE_NAME = "SERVICE_NAME";
	private final String SERVER_PORT = "SERVER_PORT";
	public final String USER_NAME = "USER_NAME";
	public static final String INSTANCE_NAME = "SISMAPP";
	public static final String mProtocolType = "_presence._tcp.";
	
	private final String mServiceName = "SISMAPP"+Math.random() * 1000;
	private String mServerPort;
	private String mUserName;
	
	public P2pServiceInfo(String port, String user){
		mServerPort = port;
		mUserName = user;
	}
	
	@SuppressLint("NewApi")
	public WifiP2pDnsSdServiceInfo getServiceInfo(){
		Map<String, String> record = new HashMap<String, String>();
		record.put(SERVICE_NAME, mServiceName);
		record.put(SERVER_PORT, mServerPort);
		record.put(USER_NAME, mUserName);
		
		return  WifiP2pDnsSdServiceInfo.newInstance(INSTANCE_NAME, mProtocolType, record);
	}
	
}
